package mlz.d_bstcp;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;

public class ServerReaderThread extends Thread{
    private Socket socket;

    public ServerReaderThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        //响应给浏览器 -> 需要遵循http的规则
        try {
            OutputStream os = socket.getOutputStream();
            //转换成 打印流 -> 做输出
            PrintStream ps = new PrintStream(os);
            /*
            数据1: HTTP/1.1 200 OK
            数据2: Content-Type:text/html;charset=UTF-8
            数据3: <div style='color:red;font-size:120px;text-align:center'>你好世界<div>
             */
            ps.println("HTTP/1.1 200 OK");
            ps.println("Content-Type:text/html;charset=UTF-8");
            ps.println("<div style='color:red;font-size:120px;text-align:center'>你好世界<div>");

            //关闭流对象
            ps.close();
            socket.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}







